﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Util
{
    public class RandomCoder
    {
        static char[] oriCharArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };

        /// <summary>
        /// 功能：生成指定位数的
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GenerateRandomCode(int length)
        {
            Random random = new Random(Guid.NewGuid().GetHashCode());
            Char[] randomCharArray = new Char[length];
            for (int i = 0; i < length; i++)
            {
                int randomIndex = random.Next(0, oriCharArray.Length);
                randomCharArray[i] = oriCharArray[randomIndex];
            }
            return new string(randomCharArray);
        }



    }
}
